<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Active Directory user authentication | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'active-directory-realm.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/active-directory-realm.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/active-directory-realm.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/active-directory-realm.html" rel="nofollow" target="_blank">../en/active-directory-realm.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="secure-cluster.html">Secure a cluster</a></span>
»
<span class="breadcrumb-link"><a href="setting-up-authentication.html">User authentication</a></span>
»
<span class="breadcrumb-node">Active Directory user authentication</span>
</div>
<div class="navheader">
<span class="prev">
<a href="realm-chains.html">« Realm chains</a>
</span>
<span class="next">
<a href="file-realm.html">File-based user authentication »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="active-directory-realm"></a>Active Directory user authentication<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/authentication/active-directory-realm.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p>You can configure Elastic Stack security features to communicate with Active
Directory to authenticate users. See <a class="xref" href="active-directory-realm.html#ad-realm-configuration" title="Configuring an Active Directory realm">Configuring an Active Directory realm</a>.</p>
<p>The security features use LDAP to communicate with Active Directory, so
<code class="literal">active_directory</code> realms are similar to <a class="xref" href="ldap-realm.html" title="LDAP user authentication"><code class="literal">ldap</code> realms</a>. Like
LDAP directories, Active Directory stores users and groups hierarchically. The
directory’s hierarchy is built from containers such as the <em>organizational unit</em>
(<code class="literal">ou</code>), <em>organization</em> (<code class="literal">o</code>), and <em>domain controller</em> (<code class="literal">dc</code>).</p>
<p>The path to an entry is a <em>Distinguished Name</em> (DN) that uniquely identifies a
user or group. User and group names typically have attributes such as a
<em>common name</em> (<code class="literal">cn</code>) or <em>unique ID</em> (<code class="literal">uid</code>). A DN is specified as a string, for
example <code class="literal">"cn=admin,dc=example,dc=com"</code> (white spaces are ignored).</p>
<p>The security features supports only Active Directory security groups. You
cannot map distribution groups to roles.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>When you use Active Directory for authentication, the username entered by
      the user is expected to match the <code class="literal">sAMAccountName</code> or <code class="literal">userPrincipalName</code>,
      not the common name.</p>
</div>
</div>
<p>The Active Directory realm authenticates users using an LDAP bind request. After
authenticating the user, the realm then searches to find the user’s entry in
Active Directory. Once the user has been found, the Active Directory realm then
retrieves the user’s group memberships from the <code class="literal">tokenGroups</code> attribute on the
user’s entry in Active Directory.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ad-realm-configuration"></a>Configuring an Active Directory realm<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/authentication/active-directory-realm.asciidoc">edit</a>
</h3>
</div></div></div>
<p>To integrate with Active Directory, you configure an <code class="literal">active_directory</code>
realm and map Active Directory users and groups to roles in the role mapping file.</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>Add a realm configuration of type <code class="literal">active_directory</code> to <code class="literal">elasticsearch.yml</code>
under the <code class="literal">xpack.security.authc.realms.active_directory</code> namespace.
At a minimum, you must specify the Active Directory <code class="literal">domain_name</code>.
If you are configuring multiple realms, you should also
explicitly set the <code class="literal">order</code> attribute to control the order in which the realms
are consulted during authentication.</p>
<p>See <a class="xref" href="security-settings.html#ref-ad-settings" title="Active Directory realm settings">Active Directory realm settings</a> for all of the options you can set for an
<code class="literal">active_directory</code> realm.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Binding to Active Directory fails if the domain name is not mapped in DNS.
      If DNS is not being provided by a Windows DNS server, add a mapping for
      the domain in the local <code class="literal">/etc/hosts</code> file.</p>
</div>
</div>
<p>For example, the following realm configuration configures Elasticsearch to connect
to <code class="literal">ldaps://example.com:636</code> to authenticate users through Active Directory:</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">xpack:
  security:
    authc:
      realms:
        active_directory:
          my_ad:
            order: 0 <a id="CO466-1"></a><i class="conum" data-value="1"></i>
            domain_name: ad.example.com
            url: ldaps://ad.example.com:636 <a id="CO466-2"></a><i class="conum" data-value="2"></i></pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO466-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The realm order controls the order in which the configured realms are checked
when authenticating a user.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO466-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>If you don’t specify the URL, it defaults to <code class="literal">ldap:&lt;domain_name&gt;:389</code>.</p>
</td>
</tr>
</table>
</div>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>When you configure realms in <code class="literal">elasticsearch.yml</code>, only the
realms you specify are used for authentication. If you also want to use the
<code class="literal">native</code> or <code class="literal">file</code> realms, you must include them in the realm chain.</p>
</div>
</div>
</li>
<li class="listitem">
<p>If you are authenticating users across multiple domains in a forest, extra
steps are required. There are a few minor differences in the configuration and
the way that users authenticate.</p>
<p>Set the <code class="literal">domain_name</code> setting to the forest root domain name.</p>
<p>You must also set the <code class="literal">url</code> setting, since you must authenticate against the
Global Catalog, which uses a different port and might not be running on every
Domain Controller.</p>
<p>For example, the following realm configuration configures Elasticsearch to connect
to specific Domain Controllers on the Global Catalog port with the domain name
set to the forest root:</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">xpack:
  security:
    authc:
      realms:
        active_directory:
          my_ad:
            order: 0
            domain_name: example.com <a id="CO467-1"></a><i class="conum" data-value="1"></i>
            url: ldaps://dc1.ad.example.com:3269, ldaps://dc2.ad.example.com:3269 <a id="CO467-2"></a><i class="conum" data-value="2"></i>
            load_balance:
              type: "round_robin" <a id="CO467-3"></a><i class="conum" data-value="3"></i></pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO467-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <code class="literal">domain_name</code> is set to the name of the root domain in the forest.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO467-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <code class="literal">url</code> value used in this example has URLs for two different Domain Controllers,
which are also Global Catalog servers. Port 3268 is the default port for unencrypted
communication with the Global Catalog; port 3269 is the default port for SSL connections.
The servers that are being connected to can be in any domain of the forest as long as
they are also Global Catalog servers.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO467-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>A load balancing setting is provided to indicate the desired behavior when choosing
the server to connect to.</p>
</td>
</tr>
</table>
</div>
<p>In this configuration, users will need to use either their full User Principal
Name (UPN) or their Down-Level Logon Name. A UPN is typically a concatenation of
the username with <code class="literal">@&lt;DOMAIN_NAME</code> such as <code class="literal">johndoe@ad.example.com</code>. The Down-Level
Logon Name is the NetBIOS domain name, followed by a <code class="literal">\</code> and the username, such as
<code class="literal">AD\johndoe</code>. Use of Down-Level Logon Name requires a connection to the regular LDAP
ports (389 or 636) in order to query the configuration container to retrieve the
domain name from the NetBIOS name.</p>
</li>
<li class="listitem">
<p>(Optional) Configure how Elasticsearch should interact with multiple Active
Directory servers.</p>
<p>The <code class="literal">load_balance.type</code> setting can be used at the realm level. Two modes of
operation are supported: failover and load balancing.  See <a class="xref" href="security-settings.html#ref-ad-settings" title="Active Directory realm settings">Active Directory realm settings</a>.</p>
</li>
<li class="listitem">
(Optional) To protect passwords,
<a class="xref" href="configuring-tls.html#tls-active-directory" title="Encrypting communications between Elasticsearch and Active Directory">encrypt communications between Elasticsearch and the Active Directory server</a>.
</li>
<li class="listitem">
Restart Elasticsearch.
</li>
<li class="listitem">
<p>Configure a bind user.</p>
<p>The Active Directory realm authenticates users using an LDAP bind request. By
default, all of the LDAP operations are run by the user that Elasticsearch is
authenticating. In some cases, regular users may not be able to access all of the
necessary items within Active Directory and a <em>bind user</em> is needed. A bind user
can be configured and is used to perform all operations other than the LDAP bind
request, which is required to authenticate the credentials provided by the user.</p>
<p>The use of a bind user enables the
<a class="xref" href="run-as-privilege.html" title="Submitting requests on behalf of other users">run as feature</a> to be used with the Active
Directory realm and the ability to maintain a set of pooled connections to
Active Directory. These pooled connection reduce the number of resources that
must be created and destroyed with every user authentication.</p>
<p>The following example shows the configuration of a bind user through the user of
the <code class="literal">bind_dn</code> and <code class="literal">secure_bind_password</code> settings:</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">xpack:
  security:
    authc:
      realms:
        active_directory:
          my_ad:
            order: 0
            domain_name: ad.example.com
            url: ldaps://ad.example.com:636
            bind_dn: es_svc_user@ad.example.com <a id="CO468-1"></a><i class="conum" data-value="1"></i></pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO468-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>This is the user that all Active Directory search requests are executed as.
Without a bind user configured, all requests run as the user that is authenticating
with Elasticsearch.</p>
</td>
</tr>
</table>
</div>
<p>The password for the <code class="literal">bind_dn</code> user should be configured by adding the
appropriate <code class="literal">secure_bind_password</code> setting to the Elasticsearch keystore. For example,
the following command adds the password for the example realm above:</p>
<div class="pre_wrapper lang-shell">
<pre class="programlisting prettyprint lang-shell">bin/elasticsearch-keystore add  \
xpack.security.authc.realms.active_directory.my_ad.secure_bind_password</pre>
</div>
<p>When a bind user is configured, connection pooling is enabled by default.
Connection pooling can be disabled using the <code class="literal">user_search.pool.enabled</code> setting.</p>
</li>
<li class="listitem">
<p>Map Active Directory users and groups to roles.</p>
<p>An integral part of a realm authentication process is to resolve the roles
associated with the authenticated user. Roles define the privileges a user has
in the cluster.</p>
<p>Since with the <code class="literal">active_directory</code> realm the users are managed externally in the
Active Directory server, the expectation is that their roles are managed there
as well. In fact, Active Directory supports the notion of groups, which often
represent user roles for different systems in the organization.</p>
<p>The <code class="literal">active_directory</code> realm enables you to map Active Directory users to roles
via their Active Directory groups or other metadata. This role mapping can be
configured via the <a class="xref" href="security-api.html#security-role-mapping-apis" title="Role mappings">role-mapping APIs</a> or by using
a file stored on each node. When a user authenticates against an Active
Directory realm, the privileges for that user are the union of all privileges
defined by the roles to which the user is mapped.</p>
<p>Within a mapping definition, you specify groups using their distinguished
names. For example, the following mapping configuration maps the Active
Directory <code class="literal">admins</code> group to both the <code class="literal">monitoring</code> and <code class="literal">user</code> roles, maps the
<code class="literal">users</code> group to the <code class="literal">user</code> role and maps the <code class="literal">John Doe</code> user to the <code class="literal">user</code>
role.</p>
<p>Configured via the role-mapping API:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /_security/role_mapping/admins
{
  "roles" : [ "monitoring" , "user" ],
  "rules" : { "field" : {
    "groups" : "cn=admins,dc=example,dc=com" <a id="CO469-1"></a><i class="conum" data-value="1"></i>
  } },
  "enabled": true
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1219.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO469-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The Active Directory distinguished name (DN) of the <code class="literal">admins</code> group.</p>
</td>
</tr>
</table>
</div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /_security/role_mapping/basic_users
{
  "roles" : [ "user" ],
  "rules" : { "any": [
    { "field" : {
      "groups" : "cn=users,dc=example,dc=com" <a id="CO470-1"></a><i class="conum" data-value="1"></i>
    } },
    { "field" : {
      "dn" : "cn=John Doe,cn=contractors,dc=example,dc=com" <a id="CO470-2"></a><i class="conum" data-value="2"></i>
    } }
  ] },
  "enabled": true
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1220.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO470-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The Active Directory distinguished name (DN) of the <code class="literal">users</code> group.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO470-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The Active Directory distinguished name (DN) of the user <code class="literal">John Doe</code>.</p>
</td>
</tr>
</table>
</div>
<p>Or, alternatively, configured via the role-mapping file:</p>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">monitoring: <a id="CO471-1"></a><i class="conum" data-value="1"></i>
  - "cn=admins,dc=example,dc=com" <a id="CO471-2"></a><i class="conum" data-value="2"></i>
user:
  - "cn=users,dc=example,dc=com" <a id="CO471-3"></a><i class="conum" data-value="3"></i>
  - "cn=admins,dc=example,dc=com"
  - "cn=John Doe,cn=contractors,dc=example,dc=com" <a id="CO471-4"></a><i class="conum" data-value="4"></i></pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO471-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The name of the role.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO471-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The Active Directory distinguished name (DN) of the <code class="literal">admins</code> group.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO471-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>The Active Directory distinguished name (DN) of the <code class="literal">users</code> group.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO471-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>The Active Directory distinguished name (DN) of the user <code class="literal">John Doe</code>.</p>
</td>
</tr>
</table>
</div>
<p>For more information, see
<a class="xref" href="mapping-roles.html" title="Mapping users and groups to roles">Mapping users and groups to roles</a>.</p>
</li>
<li class="listitem">
<p>(Optional) Configure the <code class="literal">metadata</code> setting in the Active Directory realm to
include extra properties in the user’s metadata.</p>
<p>By default, <code class="literal">ldap_dn</code> and <code class="literal">ldap_groups</code> are populated in the user’s metadata.
For more information, see
<a class="xref" href="active-directory-realm.html#ad-user-metadata" title="User metadata in Active Directory realms">User metadata in Active Directory realms</a>.</p>
</li>
</ol>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ad-user-metadata"></a>User metadata in Active Directory realms<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/authentication/active-directory-realm.asciidoc">edit</a>
</h3>
</div></div></div>
<p>When a user is authenticated via an Active Directory realm, the following
properties are populated in the user’s <em>metadata</em>:</p>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
</colgroup>
<tbody>
<tr>
<td align="left" valign="top"><p>Field</p></td>
<td align="left" valign="top"><p>Description</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">ldap_dn</code></p></td>
<td align="left" valign="top"><p>The distinguished name of the user.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">ldap_groups</code></p></td>
<td align="left" valign="top"><p>The distinguished name of each of the groups that were
                        resolved for the user (regardless of whether those
                        groups were mapped to a role).</p></td>
</tr>
</tbody>
</table>
</div>
<p>This metadata is returned in the
<a href="security-api-authenticate.html" class="ulink" target="_top">authenticate API</a> and can be used with
<a class="xref" href="field-and-document-access-control.html#templating-role-query" title="Templating a role query">templated queries</a> in roles.</p>
<p>Additional metadata can be extracted from the Active Directory server by configuring
the <code class="literal">metadata</code> setting on the Active Directory realm.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ad-load-balancing"></a>Load balancing and failover<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/authentication/active-directory-realm.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The <code class="literal">load_balance.type</code> setting can be used at the realm level to configure how
the security features should interact with multiple Active Directory servers.
Two modes of operation are supported: failover and load balancing.</p>
<p>See
<a class="xref" href="security-settings.html#load-balancing" title="Load balancing and failover">Load balancing and failover</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="active-directory-ssl"></a>Setting up SSL between Elasticsearch and Active Directory<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/authentication/active-directory-realm.asciidoc">edit</a>
</h3>
</div></div></div>
<p>See <a class="xref" href="configuring-tls.html#tls-active-directory" title="Encrypting communications between Elasticsearch and Active Directory">Encrypting communications between Elasticsearch and Active Directory</a>.</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="realm-chains.html">« Realm chains</a>
</span>
<span class="next">
<a href="file-realm.html">File-based user authentication »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>